// mdvctrl - A video-driven controller for MD-25 motor drivers
// Copyright (C) 2010  Nuno J. Silva
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <stdlib.h>

// This program works with 160x120 video frames, so the column at the
// center is the 80th one
#define CENTER_POS 80

// This module provides strategies to pick a "best" blob. Or, one
// might say, *definitions* of what a better blob is.

// Strategies take four arguments, a best center and a best area,
// which represent the current best blob, and a center and an area
// from a new blob.
//
// A strategy returns an integer which should be !0 iff the given new
// blob is better than the current "best" one.

int furthest_point (int best_center, int best_area, int center, int area) {
  // Pick the blob which is furthest away from the central
  // position.
  return (abs(center - CENTER_POS) > abs(best_center - CENTER_POS));
}

int biggest_blob (int best_center, int best_area, int center, int area) {
  // Pick the biggest blob (biggest area).
  return (area > best_area);
}
